package controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import service.ClientManager;
import vo.Client;

@Controller
public class ClientController {
	@Autowired(required=true)
	private ClientManager cm;
	/** 用户登陆 */
	@RequestMapping("/cltLogin")
	public String login(String username,String passwd,HttpServletRequest request){
		Client client = cm.login(username, passwd);
		if(client!=null){
			request.setAttribute("client", client);
			return "loginSuc";
		}
		else{
			return "login";
		}
	}
	
	/** 用户注册 */
	@RequestMapping("cltRegist")
	public String regist(Client client,HttpServletRequest request){
		System.out.println(client.getUsername()+"____________++++++");
		String name = request.getParameter("username");
		int rs = cm.regist(client);
		if(rs>0) 
			return "redirect:/regSuc.jsp";
		else return "regist";
	}
	
}
